home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 April: Mac OS SDK / Dev.CD Apr 00 SDK1.toast / Development Kits / Mac OS / Apple Guide / Engineering / Context Check Modules / Standard CC Modules / Process Context / Process.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-14  |  3.0 KB  |  114 lines  |  [TEXT/MPS ]

  1. //    Copyright:    © 1993 Apple Computer, Inc. All rights reserved.
  2. //    Author:        John R. Powers, III (original)
  3. //                Victor J. Hnyp (extensions)
  4. //                Dave Lyons (maintenance)
  5. //    Date:        13-Jan-94
  6.  
  7. /*
  8.     <3.01>    13-Jan-94 DAL    Removed check of process type (signature is enough),
  9.                             per Dec 93 code review.
  10.     ----------------------------------------------------------------------------
  11.     1.0d1e3 17-Sep-92    added type 'dfil' to match with desk accessories (JBM3)
  12.     1.0d1e2 13-Jul-92    change creator from 'ctxt' to 'reno'
  13.     1.0d1e1 22-May-92    original creation
  14. */
  15.  
  16. #pragma    load "AllHeaders.dump"
  17.  
  18. #include "Utility.h"
  19. #include "Proto.h"
  20. #include "Context.h"
  21. #include "Process.h"
  22.  
  23. /* ------------------ Forward Declaration ---------------- */
  24. short    IsProcessAvailable(ProcessTestPtr pContextRes);
  25.  
  26.  
  27. pascal OSErr main(ContextSelectorPtr msg, Size inSize,
  28.                     void* outMessage, Size* outSize, Handle /*startGlobals*/)
  29. {
  30.     Boolean        ret    =    false;
  31.     OSErr        err    =    errAECorruptData;
  32.     
  33.     if(inSize < sizeof(ContextSelector))    /* If inSize is < length of selector (a long), */
  34.         return err;                            /* return an error. Would be nice to have a specific error # */
  35.     
  36.     switch (msg->selector)
  37.     {
  38.         case isFront:
  39.         case isOpen:
  40.             ret = IsProcessAvailable((ProcessTestPtr) msg);
  41.             err    = SetContextResult(&ret, sizeof(Boolean), outMessage, outSize);
  42.             break;
  43.             
  44.         default:                            /* None of the pre-defined types. Exit with error */
  45.             break;                            /* Would be nice to have a specific error # */
  46.     }
  47.  
  48.     return err;
  49. }
  50.  
  51.  
  52. // ------------------------------------------------------------------------
  53. // Formerly TPanel::IsApplicationOk (pre-1.0d1e26)
  54. // Context check for application.
  55. // Use the Process Manager to determine the state of the application
  56. // (process) described in pContextRes.
  57. // Target application signature must be provided.
  58. // We check for processTypes of 'APPL' and 'FNDR' because
  59. // frequently our target application is the Finder.
  60.  
  61. short
  62. IsProcessAvailable(ProcessTestPtr pContextRes)
  63. {
  64.     ProcessSerialNumber    PSN;
  65.     ProcessInfoRec        info;
  66.     OSErr                err;
  67.     short                result=false;
  68.     Str31                aProcessName;
  69.     FSSpec                aProcessAppSpec;
  70.  
  71.     // Process Serial Number must be valid, make it so.
  72.     PSN.highLongOfPSN = 0;
  73.     PSN.lowLongOfPSN = kNoProcess;
  74.  
  75.     // We also have to fill-in (or make NULL) some fields.
  76.     info.processInfoLength = sizeof(ProcessInfoRec);
  77.     info.processName = aProcessName;
  78.     info.processAppSpec = &aProcessAppSpec;
  79.  
  80.     // What are we testing for?
  81.     switch (pContextRes->selector)
  82.     {
  83.         case isFront:
  84.             err = GetFrontProcess(&PSN);
  85.             if(err == noErr)
  86.             {
  87.                 err = GetProcessInformation(&PSN, &info);
  88.                 if(err == noErr)
  89.                 {
  90.                     result = (info.processSignature == pContextRes->signature);
  91.                 }
  92.             }
  93.             break;
  94.  
  95.         case isOpen:
  96.             // Search for our application (process) as the
  97.             // "current process" in background or foreground.
  98.             while (GetNextProcess(&PSN) == noErr)
  99.             {
  100.                 if(GetProcessInformation(&PSN, &info) == noErr)
  101.                 {
  102.                     if(info.processSignature == pContextRes->signature)
  103.                     {
  104.                         result = true;    // Found it.
  105.                         break;            // To exit the while…
  106.                     }
  107.                 }
  108.             }
  109.             break;
  110.     }
  111.  
  112.     return result;
  113. }
  114.